Skip to content

Conversation

@GaetanLepage
Copy link
Member

@GaetanLepage GaetanLepage commented Sep 26, 2023

-> Work done by @traxys and myself

The current maps option which allows to define keymaps in nixvim has a few flaws.
For instance, it is not possible to declare a mapping in several modes at once.

In order to wrap the underlying vim.keymap.set() function more natively, we have decided to change this fundamental option.
We have introduced a new option called keymaps which expects a list of submodule.

As an example is worth 1000 words, here is what it looks like:

# old syntax:
maps = {
  normalVisualOp."<C-m>" = ":!make<CR>";
  normal."<leader>p" = {
    action = "require('my-plugin').do_stuff";
    lua = true;
    silent = true;
    desc = "My plugin does stuff";
  };
};

# new syntax:
keymaps = [
  {
    # Default mode is "" which means normal-visual-op
    key = "<C-m>";
    action = ":!make<CR>";
  }
  {
    # Mode can be a string or a list of strings
    mode = "n";
    key = "<leader>p";
    action = "require('my-plugin').do_stuff";
    lua = true;
    # Note that all of the mapping options are now under the `options` attrs
    options = {
      silent = true;
      desc = "My plugin does stuff";
    };
  }
];

We would like to highlight that this new syntax feels way more natural regarding the neovim API.
This is the main motivation for this change as well as the numerous simplifications it thus brings.

Note: For now, the legacy maps option is still supported and will cause a warning to be shown at build time.

Relevant discussion: #576

@GaetanLepage GaetanLepage requested a review from traxys September 26, 2023 21:07
@GaetanLepage GaetanLepage force-pushed the keymaps branch 7 times, most recently from 9cc9b69 to 49c1579 Compare September 27, 2023 10:04
@GaetanLepage GaetanLepage merged commit 05b7773 into nix-community:main Oct 2, 2023
@GaetanLepage GaetanLepage deleted the keymaps branch October 2, 2023 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants